import { request } from "@umijs/max";
// 分类明细
export interface QuotationCategoryDetail {
  id: number | string;
  productId: number;
  productName: string;
  modelSpecification: string;
  quantity: number;
  originalGuidancePrice: number;
  originalSupplyPrice: number;
  sellingPrice: number;
  originalUnit: string;
  quotationTableCategoryId: number;
  quotationTableId?: number; //
  remark: string;
  // tmpCategoryId: number;
  // createBy?: string;
  // createTime?: string;
  // updateBy?: string;
  // updateTime?: string;
  // deleteFlag?: number;
  // params: Record<string, any>;
}

// 分类信息
export interface QuotationCategory {
  id: number | string;
  quotationTableId?: number; //
  quotationTableCategoryName: string;
  categoryTotalPrice: number;
  // tmpCategoryId: number;
  remark: string;
  // createBy?: string;
  // createTime?: string;
  // updateBy?: string;
  // updateTime?: string;
  // deleteFlag?: number;
  // params: Record<string, any>;
  quotationTableCategorieDetailList: QuotationCategoryDetail[];
}

// 成本项信息
export interface QuotationCostItem {
  id: number | string;
  quotationTableId?: number; //
  costItemName: string;
  costItemValue: number;
  costItemCalculateResult: number;
  remark: string;
  // createBy?: string;
  // createTime?: string;
  // updateBy?: string;
  // updateTime?: string;
  // deleteFlag?: number;
  // params: Record<string, any>;
}

// 单个报价表
export interface QuotationTable {
  id: number | string;
  quotationId: number;
  quotationTableName: string;
  totalProductPrice: number;
  totalProjectPrice: number;
  discountProductPrice: number;
  remark: string;
  // createBy?: string;
  // createTime?: string;
  // updateBy?: string;
  // updateTime?: string;
  // deleteFlag?: number;
  // params: Record<string, any>;
  quotationTableCategorieList: QuotationCategory[];
  costItemList: QuotationCostItem[];
}

// 报价单（顶层）
export interface QuotationItem {
  id?: number | string;
  businessOpportunityId: number;
  quotationNumber: string;
  quotationName: string;
  quotationFile: string;
  quotationDiscountRate: number;
  quotationDiscountPrice: number;
  quotationTotalPrice: number;
  templateType: number;
  remark: string;
  // params: Record<string, any>;
  quotationTableList: QuotationTable[];
  // createBy?: string;
  // createTime?: string;
  // updateBy?: string;
  // updateTime?: string;
  // deleteFlag?: number;
}

// ​/dev-api​/ying​/quotation​/list列表，下拉刷新
export async function getQuotationList(params: {
  pageNum: number;
  pageSize: number;
  businessOpportunityId: number;
}) {
  return request<API.ResponseData<API.QuotationList>>(
    "/api/ying/quotation/list",
    {
      method: "GET",
      params,
    }
  );
}
///dev-api/ying/quotation/delete/{id}
export async function deleteQuotation(id: number) {
  return request<API.ResponseData<any>>(`/api/ying/quotation/delete/${id}`, {
    method: "DELETE",
  });
}
// /dev-api/ying/quotation/init-data/{businessOpportunityId}
export async function initQuotationData(businessOpportunityId: number) {
  return request<API.ResponseData<API.InitQuotationData>>(
    `/api/ying/quotation/init-data/${businessOpportunityId}`,
    {
      method: "GET",
    }
  );
}
///dev-api/ying/quotation/save
export async function saveQuotation(data: API.SaveQuotationParams) {
  return request<API.ResponseData<any>>(`/api/ying/quotation/save`, {
    method: "POST",
    data,
  });
}
// /ying/quotation/detail/1
export async function getQuotationDetail(id: number) {
  return request<API.ResponseData<API.QuotationItem>>(
    `/api/ying/quotation/detail/${id}`,
    {
      method: "GET",
    }
  );
}

///dev-api/ying/quotation/export/{quotationId}
export async function exportQuotation(quotationId: number) {
  return request<API.ResponseData<any>>(
    `/api/ying/quotation/export/${quotationId}`,
    {
      method: "POST",
    }
  );
}
